package controller.command;

import model.displayer.ShapeDisplayer;
import model.displayer.ShapeDisplayerComposite;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class ShapeCombineCmd extends CommandJFxImpl
{
    private ShapeDisplayer composite;
    private Set<ShapeDisplayer> children;

    ShapeCombineCmd(Iterator<ShapeDisplayer> iter)
    {
        super(new ShapeDisplayerComposite());
        composite = shape;
        children = new HashSet<>();
        while (iter.hasNext())children.add(iter.next());
    }

    @Override
    public void execute()
    {
        for(ShapeDisplayer child:children)
        {
            composite.addChild(child);
            child.setFather(composite);
        }
    }

    @Override
    public void cancel()
    {
        for(ShapeDisplayer child:children)
        {
            child.setFather(null);
            composite.removeChild(child);
        }
    }
}
